<?php
$login = array(
	'name'	=> 'login',
	'id'	=> 'login',
	'value' => set_value('login'),
	'maxlength'	=> 80,
	'size'	=> 15,
);
if ($login_by_username AND $login_by_email) {
	$login_label = 'Email';
} else if ($login_by_username) {
	$login_label = 'Login';
} else {
	$login_label = 'Email';
}
$password = array(
	'name'	=> 'password',
	'id'	=> 'password',
	'size'	=> 15,
);
$remember = array(
	'name'	=> 'remember',
	'id'	=> 'remember',
	'value'	=> 1,
	'checked'	=> set_value('remember'),
	'style' => 'margin:0;padding:0',
);
$captcha = array(
	'name'	=> 'captcha',
	'id'	=> 'captcha',
	'maxlength'	=> 8,
);
?>
		
		<?php echo form_open($this->uri->uri_string(),array('id'=>'login_form')); ?>
		<table>
			<tr>
				<td><?php echo form_label($login_label, $login['id']); ?></td>
				<td><?php echo form_input($login); ?></td>
				<td style="color: red;"><?php echo form_error($login['name']); ?><?php echo isset($errors[$login['name']])?$errors[$login['name']]:''; ?></td>
			</tr>
			<tr>
				<td><?php echo form_label('密碼', $password['id']); ?></td>
				<td><?php echo form_password($password); ?></td>
				<td style="color: red;"><?php echo form_error($password['name']); ?><?php echo isset($errors[$password['name']])?$errors[$password['name']]:''; ?></td>
			</tr>
		
			<?php if ($show_captcha) {
				if ($use_recaptcha) { ?>
			<tr>
				<td colspan="2">
					<div id="recaptcha_image"></div>
				</td>
				<td>
					<a href="javascript:Recaptcha.reload()">Get another CAPTCHA</a>
					<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">Get an audio CAPTCHA</a></div>
					<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">Get an image CAPTCHA</a></div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="recaptcha_only_if_image">Enter the words above</div>
					<div class="recaptcha_only_if_audio">Enter the numbers you hear</div>
				</td>
				<td><input type="text" id="recaptcha_response_field" name="recaptcha_response_field" /></td>
				<td style="color: red;"><?php echo form_error('recaptcha_response_field'); ?></td>
				<?php echo $recaptcha_html; ?>
			</tr>
			<?php } else { ?>
			<tr>
				<td colspan="3">
					<p>Enter the code exactly as it appears:</p>
					<?php echo $captcha_html; ?>
				</td>
			</tr>
			<tr>
				<td><?php echo form_label('Confirmation Code', $captcha['id']); ?></td>
				<td><?php echo form_input($captcha); ?></td>
				<td style="color: red;"><?php echo form_error($captcha['name']); ?></td>
			</tr>
			<?php }
			} ?>
		
			<tr>
				<td colspan="3">
					<?php //echo form_checkbox($remember); ?>
					<?php //echo form_label('Remember me', $remember['id']); ?>
					<a href="javascript:registerForm();" class="login_link">註冊</a>
					<a href="javascript:forgotPasswordForm();" class="login_link">忘記密碼</a>
				</td>
			</tr>
			
		</table>
		<?php //echo form_submit('submit', 'Let me in'); ?>
		
		<input type="button" value="登入" name="Send" onclick="SendLoginData();"/>
		<?php echo form_close(); ?>
		
		<br/>
		<table>
			<tr>
				<td>
					<fb:login-button v="2" perms="" length="long" onlogin='window.location="https://graph.facebook.com/oauth/authorize?client_id=<?php echo $this->config->item('facebook_app_id'); ?>&redirect_uri=<?php echo site_url('auth_other/fb_signin'); ?>&amp;r="+window.location.href;'></fb:login-button>
				</td>
				<td>
					
				</td>
				<td>
					
				</td>				
				<td>
					
				</td>
				<td>
					
				</td>				
			</tr>
		</table>
		
		<p id="viewer-info"></p>
		
		<div id="fb-root"></div>
		<script type="text/javascript">
		  	FB.init({appId: "<?php echo $this->config->item('facebook_app_id'); ?>", status: true, cookie: true, xfbml: true});
		  	FB.Event.subscribe('auth.sessionChange', function(response) {
		    	if (response.session) 
		    	{
		      		// A user has logged in, and a new cookie has been saved
					//window.location.reload(true);
		    	} 
		    	else 
		    	{
		      		// The user has logged out, and the cookie has been cleared
		    	}
		  	});
		</script>
		